package com.player;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Mp3PlayerActivity extends Activity{
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.player_layout);
        
        Intent lastIntent = getIntent();
        Bundle lastBundle = lastIntent.getExtras();
        String mp3Path = lastBundle.getString("path");
        Uri myUri = Uri.parse(mp3Path);
        
        
        final Button player_start_button = (Button) findViewById(R.id.player_start_button);
        final Button player_stop_button = (Button) findViewById(R.id.player_stop_button);
        
        
        player_start_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	//setContentView(R.layout.test);
            	mediaPlayer.start();
            }
        });
        
        player_stop_button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	//setContentView(R.layout.test);
            	mediaPlayer.pause();
            }
        });
        
    	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    	try {
			mediaPlayer.setDataSource(getApplicationContext(), myUri);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	try {
			mediaPlayer.prepare();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	mediaPlayer.start();
    	
    }
    //private MediaPlayer mediaPlayer = new MediaPlayer();
    private MediaPlayer mediaPlayer = SingleMediaPlayer.getMediaPlayer();
}
